using System;
using System.Reactive.Subjects;
using System.Reactive.Linq;

namespace ReactiveChannelMessaging.WinForms;

/// <summary>
/// 响应数据消息，用于在发送请求并收到响应时通知订阅者
/// </summary>
public class ResponseDataMessage
{
    /// <summary>
    /// 发送的报文数据
    /// </summary>
    public byte[] RequestData { get; set; }
    
    /// <summary>
    /// 接收的响应数据
    /// </summary>
    public byte[] ResponseData { get; set; }
    
    /// <summary>
    /// 发送时间
    /// </summary>
    public DateTime SendTime { get; set; }
    
    /// <summary>
    /// 接收时间
    /// </summary>
    public DateTime ReceiveTime { get; set; }
    
    /// <summary>
    /// 描述信息
    /// </summary>
    public string Description { get; set; }
    
    /// <summary>
    /// 接收报文的解析结果
    /// </summary>
    public ModbusParseResult? ParsedResponse { get; set; }

    public ResponseDataMessage(byte[] requestData, byte[] responseData, DateTime sendTime, DateTime receiveTime, string description, ModbusParseResult? parsedResponse = null)
    {
        RequestData = requestData ?? throw new ArgumentNullException(nameof(requestData));
        ResponseData = responseData ?? throw new ArgumentNullException(nameof(responseData));
        SendTime = sendTime;
        ReceiveTime = receiveTime;
        Description = description ?? throw new ArgumentNullException(nameof(description));
        ParsedResponse = parsedResponse;
    }
}